﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IMark.DAO
{
    public class HoaDonModels
    {
        public static List<HOA_DON> GetAll()
        {
            using (var context = new EMartEntities())
            {
                return context.HOA_DON.OrderByDescending(u => u.MaHD).ToList();
            }
        }
        public static HOA_DON GetByID(long ID)
        {
            using (var context = new EMartEntities())
            {
                return context.HOA_DON.Find(ID);
            }
        }
        public static bool UpdateStatus(long ID)
        {
            using (var context = new EMartEntities())
            {
                try
                {
                    HOA_DON existing = context.HOA_DON.Find(ID);
                    existing.TrangThai = 1;
                    context.SaveChanges();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// Author:HTDanh
        /// Created:19/1/2015
        /// Content: lấy danh sách đơn hàng theo id của khách hàng
        /// </summary>
        /// <returns>Danh sách đơn hàng</returns>
        public static List<HOA_DON> GetByIDKH(long IDKH)
        {
            using (var context = new EMartEntities())
            {
                return context.HOA_DON.Where(w => w.MaKH == IDKH).ToList();
            }
        }
    }
}